# N0.1 三次机会猜数字
re_num =20
for i in range(3):
    num1 = input("请输入：")
    if num1.isdigit() == False:
        print("你输入的是无效数字")
    elif int(num1) > re_num:
        print("大")
    elif int(num1) < re_num:
        print("小")
    elif int(num1) == re_num:
        print("祝贺你猜对了！结果是%d，共花了%d次机会" % (re_num, i+1))
        break
if i == 2 and int(num1) != re_num:
        print("你已超过三次输入机会，游戏失败！")



# N0.2 根据分数来判断等级
grade = input("请输入你的分数：")
f = 3
# 借助标志f来判断grade的输入是否合规；f=1----整数，f=2----浮点数，f=3----其他（无效数值）
if grade.isdigit() == False:
    if grade.count('.') == 1 and (grade.replace(".","")).isdigit() == True:
        if float(grade)>= 0 and float(grade)<= 100:        # 不能写成float(grade)>=0 and float(grade)<101，尝试输入100.1
            f = 2
else:
    if int(grade)>= 0 and int(grade)<= 100:
        f = 1

if f == 3:
    print("无效分数")
else:
    grade = float(grade) if '.' in grade else int(grade)
    if(grade >= 85 and grade <= 100):
        print("优秀")
    elif(grade >= 60 and grade < 85):
        print("良好")
    else:
        print("不及格")



# N0.3  打印100-500以内的质数（1，和本身）
ff = 0
for i in range(100, 501):
    f = 0
    for y in range(1, i+1):
        if(i % y == 0):
            f+=1
    if(f == 2):
        print("%7d" % i, end = "")   # 借助输出语句来对齐格式
        ff+=1
    if(f == 2 and ff % 10 == 0):   # 控制一行最多打印10个质数, ff为打印标志
        print("")                # 可以尝试print("#”)会输出在哪



# NO.4 打印1-50的和
sum = 0
for i in range(1, 51):
    sum+=i
print("sum=%d" % sum)
